package com.zenika.training.wicket.zencontact.panel;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.ResourceModel;

import com.zenika.training.wicket.zencontact.pages.EditContactPage;
import com.zenika.training.wicket.zencontact.pages.ListContactsPage;

public class SearchPanel extends Panel {

	public SearchPanel(String id) {
		super(id);
		add(new SearchForm("searchForm"));
	}

	private class SearchForm extends Form {

		private String searchString;

		public SearchForm(String id) {
			super(id);
			add(new BookmarkablePageLink("addContact", EditContactPage.class));
			add(new TextField("searchString", new PropertyModel(this, "searchString")));
			add(new Button("searchButton", new ResourceModel("button.search")));
			setMarkupId("search-form");
		}

		public void onSubmit() {
			PageParameters params = new PageParameters();
			params.add("searchString", searchString);
			setResponsePage(ListContactsPage.class, params);
		}

	}

}
